package com.qingke.project_management.command;

import java.util.HashMap;
import java.util.Map;
import com.qingke.project_management.command_enum.CommandCode;
import com.qingke.project_management.command_impl.*;


public class CommandFactory {
	
	
	
	protected static Map<CommandCode, Class<? extends Command> > commandMap = new HashMap<CommandCode, Class<? extends Command>>();
	static{
		commandMap.put(CommandCode.COMMIT,CommitCommand.class);
		commandMap.put(CommandCode.LIST,ListCommand.class);
		commandMap.put(CommandCode.LOGIN,LoginCommand.class);
		commandMap.put(CommandCode.LOGOUT,LogoutCommand.class);
		commandMap.put(CommandCode.NEW,NewCommand.class);
		commandMap.put(CommandCode.SIGNUP,SignupCommand.class);
		commandMap.put(CommandCode.UPDATE,UpdateCommand.class);
		commandMap.put(CommandCode.HELP,HelpCommand.class);
		commandMap.put(CommandCode.EXIT,ExitCommand.class);
	}
	
	
	public Command buildCommand(CommandCode cmdCode) {
		
		try {
			Class<? extends Command> cmdClass = commandMap.get(cmdCode);
			return cmdClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	
}
